//
//  ViewController.m
//  03-Masonry使用
//
//  Created by J on 16/2/19.
//  Copyright © 2016年 J. All rights reserved.
//

#import "ViewController.h"
//define this constant if you want to use Masonry without the 'mas_' prefix
#define MAS_SHORTHAND
#define MAS_SHORTHAND_GLOBALS

#import "Masonry.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    UIView* blueView = UIView.new;
    blueView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:blueView];
    
 
    
    UIView* purpleView = UIView.new;
    purpleView.backgroundColor = [UIColor purpleColor];
    [self.view addSubview:purpleView];
    
    
    CGFloat margin = 20;
    CGFloat height = 50;
    
    [blueView makeConstraints:^(MASConstraintMaker *make) {
       

        make.left.offset(margin);
        make.right.equalTo(purpleView.left).offset(-margin);
        make.bottom.equalTo(self.view.bottom).offset(-margin);
        make.height.equalTo(height);
        
        make.top.equalTo(purpleView.top);
        make.bottom.equalTo(purpleView.bottom);
        make.width.equalTo(purpleView.width);
        
        
    }];
    
    [purpleView makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.right).offset(-margin);
     
        
    }];
    

}
- (void)test4{
    UIView* blueView = UIView.new;
    blueView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:blueView];
    
    [blueView makeConstraints:^(MASConstraintMaker *make) {
        //        make.edges.equalTo(self.view);
        make.width.equalTo(300);
        //        make.width.equalTo(self.view.width).multipliedBy(0.5);
        make.height.equalTo(self.view.height).multipliedBy(0.5).offset(-100);
        make.center.equalTo(self.view);
    }];

   
    
}

- (void)test3{
    
    
    UIView* blueView = UIView.new;
    blueView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:blueView];
    
    //距离父控件四周都是50间距
    //    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.offset(50);
    //        make.right.offset(-50);
    //        make.top.offset(50);
    //        make.bottom.offset(-50);
    //
    //
    //    }];
    
    //上面更加精简版
    //    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.top.offset(50);
    //        make.right.bottom.offset(-50);
    //
    //    }];
    
    //上面更加精简版
    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view).insets(UIEdgeInsetsMake(50, 50, 50, 50));
        
    }];
    
    /*
     约束类型:
     1.width
     */
    
}

//居中
- (void)test2{
    
    UIView* blueView = UIView.new;
    blueView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:blueView];
    
    //居中(水平+垂直)
    
    //尺寸是父控件的一半
    //边界:
    //中心点:center
    //边界:edges
    
    
    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(self.view).multipliedBy(0.5);
        make.center.mas_equalTo(self.view);
        //        make.centerX.mas_equalTo(self.view);
        //        make.centerY.mas_equalTo(self.view);
        
    }];
    

}

- (void)test1{
    
    UIView* blueView = UIView.new;
    blueView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:blueView];
    
    
    //添加新的需求
    [blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        //        make.width.mas_equalTo(@100);//mas_equalTo自动把参数包装成NSNumber或者NSValue
        //        make.height.equalTo(@100);
        //        make.right.equalTo(self.view).offset(-10);
        //        make.top.equalTo(selview).offset(20);
        //尺寸约束
        //        make.size.mas_equalTo(CGSizeMake(100, 100));
        //        //位置约束:念着父控件右边下角间距20
        //        make.center.mas_equalTo(self.view);
        
        //        make.size.equalTo([NSValue valueWithCGSize:CGSizeMake(100, 100)]);
        //            make.size.mas_equalTo(CGSizeMake(100, 100));//mas_开头的宏定义自动包装
        //        make.size.mas_equalTo(100);
        make.size.equalTo(self.view).multipliedBy(0.5);
        
        //                make.height.width.mas_equalTo(100);//mas_equalTo自动把参数包装成NSNumber或者NSValue
        make.right.equalTo(self.view).offset(-10);
        make.top.equalTo(self.view).offset(20);
        
    }];
    //
}

@end
